/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.chapter.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.chapter.entity.ChapterInfo;
import com.jeesite.modules.chapter.service.ChapterInfoService;

/**
 * chapter_infoController
 * @author lonjey
 * @version 2018-11-10
 */
@Controller
@RequestMapping(value = "${adminPath}/chapter/chapterInfo")
public class ChapterInfoController extends BaseController {

	@Autowired
	private ChapterInfoService chapterInfoService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ChapterInfo get(String chapterid, boolean isNewRecord) {
		return chapterInfoService.get(chapterid, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("chapter:chapterInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(ChapterInfo chapterInfo, Model model) {
		model.addAttribute("chapterInfo", chapterInfo);
		return "modules/chapter/chapterInfoList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("chapter:chapterInfo:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ChapterInfo> listData(ChapterInfo chapterInfo, HttpServletRequest request, HttpServletResponse response) {
		Page<ChapterInfo> page = chapterInfoService.findPage(new Page<ChapterInfo>(request, response), chapterInfo); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("chapter:chapterInfo:view")
	@RequestMapping(value = "form")
	public String form(ChapterInfo chapterInfo, Model model) {
		model.addAttribute("chapterInfo", chapterInfo);
		return "modules/chapter/chapterInfoForm";
	}

	/**
	 * 保存chapter_info
	 */
	@RequiresPermissions("chapter:chapterInfo:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ChapterInfo chapterInfo) {
		chapterInfoService.save(chapterInfo);
		return renderResult(Global.TRUE, text("保存chapter_info成功！"));
	}
	
	/**
	 * 删除chapter_info
	 */
	@RequiresPermissions("chapter:chapterInfo:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ChapterInfo chapterInfo) {
		chapterInfoService.delete(chapterInfo);
		return renderResult(Global.TRUE, text("删除chapter_info成功！"));
	}
	
}